package cn.edu.sdju.fengguoyu.ahoedgemonitor;

import javafx.geometry.Bounds;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import java.io.IOException;

public class RegisterServerSprite extends ServerSprite {
    private static Image icon = null;

    public RegisterServerSprite() {
        if (icon == null) {
            try {
                icon = new Image(App.class.getResource( "register_server_icon.png").openStream());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        super.label = "RegisterServer";
    }
    public RegisterServerSprite(double x, double y) {
        this();
        super.width = 78;
        super.height = 93;
        this.x = x;
        this.y = y;
    }

    public void draw(GraphicsContext gc) {
        gc.drawImage(icon,x, y, width, height);
        gc.setFont(new Font("Arial", 14));
        gc.setFill(Color.BLUE);
        Text text = new Text(label);
        text.setFont(new Font("Arial", 14));

        Bounds bounds = text.getBoundsInLocal();
        double textWidth = bounds.getWidth();
        gc.fillText(label,x - (textWidth/2) + (width/2), y+height+8);
    }
}
